package top.jojoace.demo;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;
import top.jojoace.demo.Configuration.ConditionalConfiguration;
import top.jojoace.demo.ConfigurationSelector.UserConfigurationSelector;
import top.jojoace.demo.Dao.ConditionUser;
import top.jojoace.demo.Dao.User3;
import top.jojoace.demo.Dao.UserInterface;

/**
 * @author 陈Ser
 * @ClassName Import2Application
 * @description: TODO
 * @Date 2021/10/29 17:15
 * @Version 1.0
 */


/**
 * <h2>@Import( Configuration.class 或 ConfigurationSelector.class )</h2>
 * 单独的导入 配置类 或者 配置选择类
 */
@Import(UserConfigurationSelector.class)    // UserConfiguration 和 ConditionalConfiguration配置选择类
public class Import2Application {
    public static void main(String[] args) {
        ConfigurableApplicationContext context =
                new SpringApplicationBuilder(Import2Application.class)
                        .web(WebApplicationType.NONE)   //关闭Web
                        .run(args);
        /**
         * 没有web需要的相关类，导致无法启动web报错。
         * 故，使用web(WebApplicationType.NONE)关闭Web的启动。
         */

        User3 user3 = (User3) context.getBean("user3");
        user3.sayClass();

        ConditionUser conditionUser = (ConditionUser) context.getBean("conditionUser");
        conditionUser.sayClass();
    }
}
